#pragma once

#include <list>
#include <mutex>  // NOLINT
#include <unordered_map>
#include <vector>

#include "buffer/replacer.h"
#include "common/config.h"

class LRUReplacer : public Replacer {
    using mutex_t = std::mutex;

   public:
    /**
     * Create a new LRUReplacer.
     * @param num_pages the maximum number of pages the LRUReplacer will be required to store
     */
    explicit LRUReplacer(size_t num_pages);

    /**
     * Destroys the LRUReplacer.
     */
    ~LRUReplacer() override;

    bool Victim(frame_id_t *frame_id) override;

    void Pin(frame_id_t frame_id) override;

    void Unpin(frame_id_t frame_id) override;

    size_t Size() override;

   private:
    mutex_t mutex;
    size_t capacity;
    std::list<frame_id_t> lst;
    std::unordered_map<frame_id_t, std::list<frame_id_t>::iterator> hash;
};